//
//  UIImage+WebImage.swift
//  MQLWeibo
//
//  Created by MQL-IT on 2017/3/26.
//  Copyright © 2017年 MQL-IT. All rights reserved.
//

import SDWebImage
extension UIImageView {
    /// 隔离SDWebImage 设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: 图片连接
    ///   - placeHolderImage: 占位图像
    ///   - isAvatar: 是否是头像
    func ql_setImage(urlString: String?, placeHolderImage: UIImage?, isAvatar: Bool = false) {
        //处理url
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
            image = placeHolderImage
            return
        }
        sd_setImageWithPreviousCachedImage(with: url, placeholderImage: placeHolderImage, options: [], progress: nil) {[weak self] (image, _, _, _) in
            // 完成回调 - 判断是否是头像
            if isAvatar {
                self?.image = image?.ql_avatarImage(size: self?.bounds.size)
            }
            
        }
    }
}
